import piniaPersistConfig from "@/config/piniaPersist";
import { defineStore } from "pinia";
import { MenuState } from "../interface";

export const useMenuStore = defineStore({
  id: "geeker-menu",
  state: (): MenuState => ({
    activeRouteList: [],
    subMenuList: [],
    activeMenuIdx: -1
  }),
  actions: {
    // setMenuIdx
    setMenuIdx(menuIdx: number): void {
      this.activeMenuIdx = menuIdx;
    },
    // updateActiveRoute
    updateActiveRoute(activeRoute: string): void {
      this.activeRouteList[this.activeMenuIdx] = activeRoute;
    },
    // setSubMenuList
    setSubMenuList(menuList: Menu.MenuOptions[]): void {
      this.subMenuList = menuList;
    },
    setActiveRouteList(activeRouteList: string[]): void {
      this.activeRouteList = activeRouteList;
    }
  },
  persist: piniaPersistConfig("geeker-menu")
});
